#ifndef _ASYN_OPERATION_H_
#define _ASYN_OPERATION_H_


typedef ULONG ERROR_CODE;
typedef BYTE* BUFFER_PTR;
typedef ULONG BUFFER_SIZE;

// Do not use LIBUV files and pipe operations 
// Because the encapsulation is a little bit inappropriate.
// Re-encapsulation of an IO framework for file operations


#pragma pack(1)

typedef enum TagAddrType {
	addr_socket_v4	= 0,
	addr_socket_v6	= 1,
	addr_file		= 2,
	addr_pipe		= 3
}AddrType;


typedef struct Tagos_io_fd {
	AddrType		type;
	char			address[260];
	unsigned long	port;

	union {
		os_sock_t	socket;
		os_fd_t		file;
		os_pipe_t	pipe;
	}fd;

}os_io_fd;



enum optype {

	OP_NULL				= 0,
	OP_TCPSOCKET_CONNECT,
	OP_TCPSOCKET_RECV,
	OP_TCPSOCKET_SEND,
	OP_TCPSOCKET_ACCEPT,
	OP_TCPSOCKET_BIND,

	OP_CANCEL,
	OP_TIMEOUT,
	OP_ERROR,
	OP_OPENFDRROR,

	OP_EXCEPTION		= 400,
	UNKNOWN_EXCEPTION,

	OP_EOF				= 10000

};
#pragma pack()

interface IIoOperation : public IBase
{
		std_method(SetOpType)(optype op)												= 0;
		std_method_(optype, GetOpType)()												= 0;
	    std_method(SetId)(ULONG lId) 													= 0;
		std_method_(ULONG, GetId)()														= 0;
        std_method(SetResult)(ERROR_CODE lErrorCode,
							 ULONG lTransferedBytes) 									= 0;
        std_method(GetResult)(ERROR_CODE *pErrorCode,
        					ULONG *pTransferedBytes) 									= 0;
		std_method(SetIoParam)(ULONG lIoStartPos, ULONG lIoExpectBytes)					= 0;
		std_method(GetIoParam)(ULONG* pIoStartPos, ULONG* pIoExpectBytes)				= 0;
		std_method(AttachIoBuf)(BUFFER_PTR buf, ULONG lIoStartPos, ULONG lIoExpectBytes)= 0;
		std_method(SetIoLen)(ULONG lIoSize)												= 0;
		std_method_(ULONG, GetIoLen)()													= 0;
		std_method(ClearBuf)()															= 0;
		std_method_(BUFFER_PTR, GetIo)(ULONG Pos)										= 0;
		std_method(SetResultInterface)(IBase* lOperationPos)							= 0;
		std_method(GetResultInterface)(IBase** pOperationPos)							= 0;
		std_method(Cancel)()															= 0;
		std_method(SetBind)(os_io_fd fd)												= 0;
		std_method_(os_io_fd*, GetBind)()												= 0;
		std_method_(const char*,GetAddress)()											= 0;
		std_method_(unsigned long,GetConPort)()											= 0;
		std_method(SetAddress)(const char* addr)										= 0;
		std_method(SetConPort)(unsigned long uport)										= 0;
		std_method(Post)()																= 0;
		std_method(SetAsynRW)(bool bstart)												= 0;
		std_method_(bool, IsAsynRWThread)()												= 0;
		std_method(SetMultiThread)(bool bstart)											= 0;
		std_method_(bool, GetMultiThread)()												= 0;
};


_DEFINE_IID(IIoOperation, "{D34BE927-B63E-4B0C-9BE7-D4E123A05B2B}");


interface IIoOperationEvents
{
    std_method(OnOperationComplete)(IIoOperation *pOperation)           = 0;
};
//_DEFINE_IID(IIoOperationEvents, "{2D2E1C66-AB07-430F-9C9A-AF9855AC7071}");


#endif